var player1Hp= 80020000;
var player2Hp= 80003000;
var playerOneBaiFenZhi=0;
var playerTwoBaiFenZhi=0;
var playerOneActSum = 0;
var playerTwoActSum = 0;
var flag = 1;
var interTime = false;

function getArray(){
	let arr=document.getElementById("arr").children
	let array=new Array();
	for(var i=0;i<arr.length;i++){
		array[i]=arr[i].innerHTML;
	}
	console.log(array);
	
	arr[2].style.color="red";
	console.log(arr[2].style.color)
	arr[3].innerHTML="这是一段测试文字"
}


// 战斗,判断是玩家1还是2,伤害血量总值--
function testAct(){
	if(flag==1){
		// 是玩家1的回合
		

		flag=2;
	}else{
		// 这是玩家2的回合
		
		flag=1;
	}
}

// 开始战斗
function startAct(){
	if(interTime==false){
		// 是空就代表定时器未启用
		interTime=window.setInterval("testAct()",1000);
	}
}

//停止战斗
function stopAct(){
	// 非空就代表定时器在转动
	if(interTime!=null){
		window.clearInterval(interTime);
		interTime=false;
	}
}

// 获取一百以内的随机数
function getRandom(){
	return(Math.floor(Math.random()*100));
}


//获取进度 1表示玩家1,2表示玩家2,返回百分之x的进度
function getJinDu(flag){
	// 判断如果两个其中有一个是0那么就代表现在没有玩家的血条百分之1的参数
	if(playerOneBaiFenZhi==0||playerTwoBaiFenZhi==0){
		playerOneBaiFenZhi=Math.floor(player1Hp*0.01);
		playerTwoBaiFenZhi=Math.floor(player2Hp*0.01);
	}
	// 损失血量/百分之一.比如100/49,是2,那么就是2个百分比
	if(flag==1){
		return 100 - (playerOneActSum/playerOneBaiFenZhi);
	}else if(flag==2){
		return 100 - (playerTwoActSum/playerTwoBaiFenZhi);
	}
}

//显示血条百分比
function showHp(jindu){
	var hp1=document.getElementById('oneHps').style.width=jindu+'%';
	var hp2=document.getElementById('twoHps').style.width=jindu+'%';
	console.log(hp1+"分割线"+hp2);
}


// 显示战斗信息
function showInfomation(Array){
	
	
	var testDiv=document.getElementById("battle");
	var huanhang=document.createElement("br");
	testDiv.appendChild(huanhang);
	console.log(wanjia.style.color)
}

//抽奖概率
function getLuck(param){
	
	
	
	
}

function testFunction(){
	let luck=0;
	let luckSum=0;
	let even="抽中了";
	for(var i=0;i<100;i++){
		if(chouJiang()==true){
			luck++;
		}else{
			even="没抽中";
		}
		luckSum++;
		console.log("这是第"+luckSum+"次抽奖,"+"这次"+even+",当前总概率为:"+luck/luckSum);
	}
}

function chouJiang(){
	// 测试10%的概率(幸运越高,数轴越大,概率越大)
	var luck=document.getElementById('luckText').value;
	if(luck.length<=0){
		luck=10000;
	} else if(luck>100000){
		luck=100;
		console.log("作弊你就死,概率0.001")
	}
	
	
	var luckSum=false;
	var maxRandom=Math.floor(Math.random()*100000)
	if(maxRandom<=luck){
		console.log("中了:"+maxRandom+":"+luck);
		luckSum=true;
	}else{
		console.log("没中:"+maxRandom+":"+luck);
		luckSum++;
		if(luckSum==true){
			luckSum=false;
		}
	}
	return luckSum;
}

/* 
获得实际伤害 
实际伤害= 物理伤害- {(物理伤害(att)+[力量*2])-对方防御}*对方护甲比,注意护甲比是小数累加
*/
function attAllSum(att,myStr,yourHujia,yourDef){
	
	var attSUm = att- Math.floor((att+(myStr*2)-yourDef)*yourHujia);
	return attSUm;
}
function attAllSumTest(){
	var sum= attAllSum(251241,4440,0.24,5000);
	console.log(sum);
}


/*
 获得真实伤害 
 真实伤害=真伤量-[真伤*=对方抵抗比]]
 */
function getZhenShang(myZhenshang,yourDikang){
	let sum=myZhenshang-(Math.floor(myZhenshang*yourDikang));
	console.log(sum);
}

/* 
 获得吸血量
 吸血量=实际抵消伤害*吸血比重
 */
function getXiXue(myAtt,xixue){
	let sum=Math.floor(myAtt*xixue);
	return sum;
}

/* 
	回避与否
	建立数轴分别为最大概率[0-100000]闪避概率[0-真实回避概率]不中概率[真实回避-100000]]	
 */
function isHuiBi(myHuibi,yourMingzhong){
	var sum = false;
	var cha = 0;
	if(myHuibi <yourMingzhong ){
		sum = true;
		return sum;
	}
	if(myHuibi > yourMingzhong){
		if(cha!=0){
			cha=0;
		}
		cha = myHuibi-yourMingzhong;
		sum = chanceResult(cha);
	}
	return sum;
}



/* 
	暴击与否
	建立数轴分别为最大概率[0-100000]暴击概率[0-真实暴击概率]不中概率[真实暴击-100000]]
 */
function isBaoJi(myBaoji,yourkangBao){
	let sum = false;
	let cha = 0;
	if(myBaoji<yourkangBao){
		return sum;
	}
	
	if(myBaoji>yourkangBao){
		if(cha!=0){
			cha = 0;
		}
		cha = myBaoji-yourkangBao;
		sum=chanceResult(cha);
		return sum;
	}
	return sum;
}
// 结算暴击伤害,返回的是经过结算后的伤害,暴击就返回结算后的暴击伤害,如果不暴击就返回原伤害
function BaoJiAtt(shijishanghai,shijibaojishanghaibizhi,mybaoji,yourkangBao){
	let flag=isBaoJi(mybaoji,yourkangBao);
	if(flag==true){
		shijishanghai+=(shijishanghai*shijibaojishanghaibizhi);
		return shijishanghai;
	}else{
		return shijishanghai;
	}
	return shijishanghai;
}




/* 
	幸运伤害
	活动抽奖的幸运是固定幸运,其他一切都与幸运有关
	技能加成的幸运是直接调用getLuck()+luck,再调用本方法
*/
function isLuck(luck){
	let flag = false;
	if( chanceResult(luck) == true ){
		flag = true;
		return flag;
	}else{
		return flag
	}
	return flag;
}

// 读取本地
// var ipAddress = null;

// $(document).ready(function () {
//     $.ajax({
//         url: '../data.json',
//         async: false,
//         success: function (data) {
//             ipAddress = data.ip;
//         }
//     });
// });


/* 
	获得概率结果,最大为100000
 */
function chanceResult(param){
	
	var result = false;
	var randomNumber = Math.floor(Math.random()*100000);
	if(randomNumber <= param){
		result = true;
		return result;
	}else{
		return result;
	}
	
	return result;
}

function chanceResultTest(){
	// 测试10%的概率
	let result = 0;
	let index = 0;
	for(i = 1000;i>0;i--){
		if(chanceResult(10000)==true){
			result++;
		}
		index++;
		console.log("当前是第:"+index+"次判断,"+"一共判定成功:"+result+"次,当前总概率为:"+(result/index));
	}
}


/* 
	获取技能参数,然后随机获取其中一个主动技能,第二个方法结算技能产生的伤害
	等后端
 */

/* 
	初始化称号参数加成,然后加成怪物或者人
	等后端
 */



/* 
	初始化被动技能,加入主角参数或者怪物参数
	等后端
	
 */